/**
 * Created by JetBrains WebStorm.
 * User: Tonis
 * Date: 25.02.12
 * Time: 21:04
 * To change this template use File | Settings | File Templates.
 */
var Mode = Class.extend({
    init:function (x, y, w, h, text,fill) {

        this.x = x || 0;
        this.y = y || 0;
        this.w = w || 1;
        this.h = h || 1;
        this.fill = fill || '#AAAAAA';
        this.text = text || "default";
        this.border = false;
    },
    draw:function () {
        ctx.fillStyle = this.fill;
        ctx.fillRect(this.x, this.y, this.w, this.h);
        ctx.fillStyle = "#000000";
        ctx.font="30px Arial";
        ctx.fillText(this.text, this.x + 10, this.y + (this.h /2) + 10);
        if (this.border){
            ctx.strokeStyle = "#FF0000";
            ctx.strokeRect(this.x-1, this.y-1, this.w+1, this.h+1);

        }
    },
    setBorder: function(border){
        this.border = border;
    },
    isWithinBounds:function (mx, my) {
        return  (this.x <= mx) && (this.x + this.w >= mx) &&
            (this.y <= my) && (this.y + this.h >= my);
    }
});

var GameModes = Class.extend({
    gameModeList: new Array(),
    init:function (canvas) {
        canvas.addEventListener('mousedown', this.mouseDown );
        canvas.addEventListener('mousemove', this.mouseMove);
    },
    addMode:function (mode) {
        this.gameModeList.push(mode);
    },
    mouseDown:function (e) {
        var gameModeList = gameModes.getGameModeList();
        var mouse = getMouse(e);
        var mx = mouse.x;
        var my = mouse.y;
        //alert(gameModeList.length);
        var l = gameModeList.length;
        for (var i = l - 1; i >= 0; i--) {
            if (gameModeList[i].isWithinBounds(mx, my)) {
                gameModeSelected = true;
            }
        }


    },
    mouseMove: function(e){
        var gameModeList = gameModes.getGameModeList();
        var mouse = getMouse(e);
        var mx = mouse.x;
        var my = mouse.y
        var l = gameModeList.length;
        for (var i = l - 1; i >= 0; i--) {
            if (gameModeList[i].isWithinBounds(mx, my)) {
                gameModeList[i].setBorder(true);

            }else{
                gameModeList[i].setBorder(false);
            }
        }

    },
    getGameModeList: function(){
        return this.gameModeList;
    },
    draw:function () {
        for (var i = 0; i < this.gameModeList.length; i++) {
            this.gameModeList[i].draw();
        }
    }


});




